/**
 * tigerrad
 * fall 2006
 */

#ifndef _MODEL_H
#define _MODEL_H

#include "Util.h"


/**
 * Triangle indices.
 */
class Triangle
{
	public:
		Triangle(unsigned int v0, unsigned int v1, unsigned int v2)
		{
			v[0] = n[0] = v0;
			v[1] = n[1] = v1;
			v[2] = n[2] = v2;
		}
		
		Triangle(unsigned int v0, unsigned int v1, unsigned int v2,
				unsigned int n0, unsigned int n1, unsigned int n2)
		{
			v[0] = v0;
			v[1] = v1;
			v[2] = v2;
			n[0] = n0;
			n[1] = n1;
			n[2] = n2;
		}

		unsigned int v[3];
		unsigned int n[3];
};

/**
 * Simple material
 */
class Material
{
	public:
		/** Constructor. Default to white. */
		Material() : diffuse(1.0, 1.0, 1.0) {}
		Vec3 diffuse;
};

/**
 * Part of a Model.
 */
class Part
{
	public:
		/**
		 * Part vertices.
		 */
		std::vector<Vec3> verts;

		/**
		 * Vertice normals.
		 */
		std::vector<Vec3> norms;

		/**
		 * Triangles.
		 */
		std::vector<Triangle> tris;

		/**
		 * Default material for this Part.
		 */
		Material mat;
};

typedef boost::shared_ptr<Part> PartPtr;

/**
 * 3D Model, which is a collection of Part instances.
 */
class Model
{
	public:
		/**
		 * Constructor.
		 * @param Unique Model name.
		 */
		Model(const std::string& n) : _name(n) {}
	
		/**
		 * Part instances that make up this Model.
		 */
		std::vector<PartPtr> parts;

		/**
		 * Return the unique name.
		 */
		std::string getName() { return _name; }

		/**
		 * Translate each vertex in the model.
		 */
		void translate(const Vec3& v);

		/**
		 * Scale each vertex in the model.
		 */
		void scale(const float s);


		/**
		 * Translate each vertex in the model.
		 */
        void loadOBJ(const std::string& objfile);
		
	private:
        void skipLine(std::istream& is);
		std::string _name;
};

typedef boost::shared_ptr<Model> ModelPtr;

#endif 

